﻿using System;
using System.Text;
using System.Threading.Tasks;

namespace SwissTransTracker
{
    public static partial class Api
    {
        /// <summary>
        ///     Returans all the possible connections between 2 places
        /// </summary>
        /// <param name="from">where you start from</param>
        /// <param name="to">where you go to</param>
        /// <param name="date">the date you want to travel on</param>
        /// <param name="isArrivalTime">wheter or not the specified time is the arrival time</param>
        /// <returns>A list containing all found connections</returns>
        public static Task<ConnectionList> GetConnections(string from, string to, DateTime date, bool isArrivalTime)
        {
            var sb = new StringBuilder("http://transport.opendata.ch/v1/connections?");
            sb.Append("from=").Append(from);
            sb.Append("&to=").Append(to);
            sb.Append("&date=").Append(FormatDate(date));
            sb.Append("&time=").Append(FormatTime(date));
            sb.Append("&isArrivalTime=").Append(FormatBool(isArrivalTime));
            sb.Append("&limit=6");
            return Fetch<ConnectionList>(sb.ToString());
        }

        /// <summary>
        ///     Returans all the possible connections between 2 places
        /// </summary>
        /// <param name="from">where you start from</param>
        /// <param name="to">where you go to</param>
        /// <param name="date">the date you want to travel on</param>
        /// <param name="isArrivalTime">wheter or not the specified time is the arrival time</param>
        /// <param name="directOnly">wheter or not you should consider transfers during you journey</param>
        /// <param name="sleeperOnly">wheter or not only to take transports with beds</param>
        /// <param name="couchetteOnly">wheter or not onky to take transports with couchettes</param>
        /// <param name="bikeOnly">wheter or not only to accept transports you can go on with your bike</param>
        /// <returns>A list containing all found connections</returns>
        public static Task<ConnectionList> GetConnections(string from, string to, DateTime date, bool isArrivalTime,
                                                          bool directOnly, bool sleeperOnly, bool couchetteOnly,
                                                          bool bikeOnly)
        {
            var sb = new StringBuilder("http://transport.opendata.ch/v1/connections?");
            sb.Append("from=").Append(from);
            sb.Append("&to=").Append(to);
            sb.Append("&date=").Append(FormatDate(date));
            sb.Append("&time=").Append(FormatTime(date));
            sb.Append("&isArrivalTime=").Append(FormatBool(isArrivalTime));
            sb.Append("&limit=6");
            sb.Append("&direct=").Append(FormatBool(directOnly));
            sb.Append("&sleeper=").Append(FormatBool(sleeperOnly));
            sb.Append("&couchette=").Append(FormatBool(couchetteOnly));
            sb.Append("&bike=").Append(FormatBool(bikeOnly));
            return Fetch<ConnectionList>(sb.ToString());
        }
    }
}